///*
// * CN_ATTACK.cpp
// *
// *  Created on: 2013. 5. 21.
// *      Author: the2
// */
//
//#include "../../User.h"
//#include "CN_ATTACK.h"
//
//#include "../../NLogic/Space.h"
//#include "../../NLogic/Monster.h"
//
//namespace ProjectZ { namespace NCommand { namespace NBattle {
//
//void CN_ATTACK::OnExecute(User * pUser, ::Network::Packet * pPacket)
//{
//	PREPARE_PACKET;
//
//	char effect;
//	int damage_value;
//	int defender_gid;
//	int8_t defender_ismonster;
//	int16_t degree;
//	int8_t statetype;
//	int8_t ismonster;
//	int attacker_gid;
//
//	*pPacket >> effect >> damage_value >> defender_gid;
//	*pPacket >> defender_ismonster >> degree >> statetype >> ismonster >> attacker_gid;
//
//	if (0 == ismonster && 1 == defender_ismonster) // ATTACK USER TO MONSTER
//	{
//		DEBUGLOG("CN_ATTACK_DUNGEON::processPVP ATTACK USER TO MONSTER!!");
//		return;
//	}
//
//	if (1 == ismonster && 0 == defender_ismonster)	// ATTACK MONSTER TO USER
//	{
//		DEBUGLOG("CN_ATTACK_DUNGEON::processPVP ATTACK MONSTER TO USER!!");
//		return;
//	}
//
//	if (1 == ismonster && 1 == defender_ismonster)	// ATTACK MONSTER TO MONSTER
//	{
//		DEBUGLOG("CN_ATTACK_DUNGEON::processPVP ATTACK MONSTER TO MONSTER!!");
//		return;
//	}
//
//	// ATTACK USER TO USER
//
//	NLogic::Space * pSpace	= pUser->GetSpace();
//	if (pSpace == NULL)
//	{
//		DEBUGLOG("CN_ATTACK_DUNGEON::processPVP pSpace is NULL!!!");
//		return;
//	}
//
//	User * pTarget	= pSpace->FindUser(defender_gid);
//	if (pTarget == NULL)
//		return;
//
//	pTarget->player_info.HP -= damage_value;
//
//	if (pTarget->player_info.HP <= 0)
//	{
//		pTarget->player_info.HP = 0;
//		pSpace->GetData()._winnerGID = pTarget->player_info.FighterGID;
//	}
//
//	{
//		::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();
//		*pAck << effect;
//		*pAck << damage_value;
//		*pAck << defender_gid;
//		*pAck << defender_ismonster;
//		*pAck << pTarget->player_info.HP;
//		*pAck << degree;
//		*pAck << ismonster;
//		*pAck << attacker_gid;
//
//		pAck->MakePacket(CMD_SN_ATTACK);
//		pSpace->SendAllExceptMe(pAck, pUser);
//	}
//
//
//	{
//		::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();
//
//		*pAck << defender_gid;
//		*pAck << pTarget->player_info.HP;
//		*pAck << ismonster;
//
//		pAck->MakePacket(CMD_SC_ATTACK);
//		pUser->Send(pAck);
//	}
//
//	//			::Network::Packet * pNoti2 = ::Network::GETPACKETPOOL()->SEND_NEW();
//	//			pNoti2->MsgCat("%d%d%c", defender_gid, targethp, ismonster);
//	//			pNoti2->MakePacket(CMD_SC_ATTACK);
//	//			pUser->Send(pNoti2);
//
//
//
//
////	PREPARE_PACKET;
////	Player_Info & player_info = pUser->player_info;
////
////	bool bFightEnd = false;
////	//int winner_gid = 0;
////	//int loser_gid = 0;
////
////	int effect = 0;
////	int damage_value = 0;
////	int defender_gid = 0;
////	int degree = 0;
////	int ismonster = 0;
////	int defender_ismonster = 0;
////	int attacker_gid = 0;
////
////	pPacket->ParseMsg("%c%d%d%c%2d%c%d", &effect, &damage_value, &defender_gid, &defender_ismonster, &degree, &ismonster, &attacker_gid);
////
////	::Logger::GETLOG()->ToFile(::Logger::DEBUG, "CN_ATTACK GID : %d : effect=%d damage_value=%d defender_gid=%d defender_ismonster=%d degree=%d ismonster=%d attacker_gid=%d",
////			pUser->GetGID(), effect, damage_value, defender_gid, defender_ismonster, degree, ismonster, attacker_gid);
////
////	if( ismonster == false )
////	{
////		player_info.degree = degree;
////	}
////
////	if( defender_gid < 0 )
////	{
////		::Logger::GETLOG()->ToFile(::Logger::DEBUG, "CN_ATTACK, wrong defender_gid", defender_gid);
////		return;
////	}
////
////	NLogic::Space * pSpace = pUser->GetSpace();
////	if (NULL == pSpace)
////	{
////		::Logger::GETLOG()->ToFile(::Logger::DEBUG, "WARNING: CN_ATTACK GID %d, pSpace is NULL", pUser->GetGID());
////		return;
////	}
////
////	int targethp = 0;
////
////	if( ismonster == false )
////	{
////		if( defender_ismonster == false )	// user->user
////		{
////			User * pTarget = pSpace->FindUser(defender_gid);
////			if (NULL == pTarget)
////				return;
////
////			attackUserToUser(pUser, pTarget, pSpace, damage_value, targethp);
////		}
////		else	// user->monster
////		{
////			NLogic::Monster * pMonster = pSpace->GetMonster(defender_gid);
////			if (NULL == pMonster)
////				return;
////
////			attackUserToMonster(pSpace, pMonster, defender_gid, damage_value, targethp);
////		}
////
////		::Logger::GETLOG()->ToFile(::Logger::DEBUG, "CN_ATTACK GID %d, damage(%d), targetHP(%d), bFightEnd=%d", pUser->GetGID(),
////					damage_value, targethp, bFightEnd);
////
////		{
////			::Network::Packet * pNoti = ::Network::GETPACKETPOOL()->SEND_NEW();
////			pNoti->MsgCat("%c%d%d%c%d%2d%c%d", effect, damage_value, defender_gid, defender_ismonster, targethp, degree, ismonster, attacker_gid);
////			pNoti->MakePacket(CMD_SN_ATTACK);
////<<<<<<< .mine
////		pSpace->SendAllExceptMe(pNoti, pUser);
////=======
////
////			pSpace->SendToMessageExceptMe(pNoti, pUser->GetGID());
////		}
////>>>>>>> .r774
////
////		{
////			::Network::Packet * pNoti2 = ::Network::GETPACKETPOOL()->SEND_NEW();
////			pNoti2->MsgCat("%d%d%c", defender_gid, targethp, ismonster);
////			pNoti2->MakePacket(CMD_SC_ATTACK);
////			pUser->Send(pNoti2);
////		}
////
////		//
////<<<<<<< .mine
//////		if( bFightEnd == true )
//////		{
//////			::Network::Packet * pNoti3 = ::Network::GETPACKETPOOL()->SEND_NEW();
//////			pNoti3->MsgCat("%d%d", winner_gid, loser_gid);
//////			pNoti3->MakePacket(CMD_SN_FIGHT_END);
//////			pSpace->SendToMessageAll(pNoti3);
//////
//////			::Logger::GETLOG()->ToFile(::Logger::DEBUG, "\t\tsend SN_FIGHT_END, winner_gid=%d, loser_gid=%d", winner_gid, loser_gid);
//////		}
////=======
////		if( bFightEnd == true )
////		{
////			::Network::Packet * pNoti3 = ::Network::GETPACKETPOOL()->SEND_NEW();
////			pNoti3->MsgCat("%d%d", winner_gid, loser_gid);
////			pNoti3->MakePacket(CMD_SN_FIGHT_END);
////			pSpace->SendToMessageAll(pNoti3);
////
////			::Logger::GETLOG()->ToFile(::Logger::DEBUG, "\t\tsend SN_FIGHT_END, winner_gid=%d, loser_gid=%d", winner_gid, loser_gid);
////		}
////>>>>>>> .r774
////	}
////	else
////	{
////		if( defender_ismonster == false )	// monster->user
////		{
////			User * pTarget = pSpace->FindUser(defender_gid);
////			if (NULL == pTarget)
////				return;
////
////			attackMonsterToUser(pUser, pTarget, pSpace, damage_value, targethp);
////
////			::Logger::GETLOG()->ToFile(::Logger::DEBUG, "CN_ATTACK GID %d, damage(%d), targetHP(%d), bFightEnd=%d", pUser->GetGID(),
////						damage_value, targethp, bFightEnd);
////
////<<<<<<< .mine
////			::Network::Packet * pNoti4 = ::Network::GETPACKETPOOL()->SEND_NEW();
////			//pNoti->MsgCat("%c%d%d%d%2d%c%d", effect, damage_value, defender_gid, target_player_info.HP, degree, ismonster, attacker_gid);
////			pNoti4->MsgCat("%c%d%d%c%d%2d%c%d", effect, damage_value, defender_gid, defender_ismonster, targethp, degree, ismonster, attacker_gid);
////			pNoti4->MakePacket(CMD_SN_ATTACK);
////=======
////			{
////				::Network::Packet * pNoti4 = ::Network::GETPACKETPOOL()->SEND_NEW();
////				//pNoti->MsgCat("%c%d%d%d%2d%c%d", effect, damage_value, defender_gid, target_player_info.HP, degree, ismonster, attacker_gid);
////				pNoti4->MsgCat("%c%d%d%c%d%2d%c%d", effect, damage_value, defender_gid, defender_ismonster, target_player_info.HP, degree, ismonster, attacker_gid);
////				pNoti4->MakePacket(CMD_SN_ATTACK);
////>>>>>>> .r774
////
////<<<<<<< .mine
////			pSpace->SendAllExceptMe(pNoti4, pUser);
////=======
////				pSpace->SendToMessageExceptMe(pNoti4, pUser->GetGID());
////			}
////>>>>>>> .r774
////
////<<<<<<< .mine
////			::Network::Packet * pNoti5 = ::Network::GETPACKETPOOL()->SEND_NEW();
////			pNoti5->MsgCat("%d%d%c", defender_gid, targethp, ismonster);
////			pNoti5->MakePacket(CMD_SC_ATTACK);
////			pUser->Send(pNoti5);
////=======
////			{
////				::Network::Packet * pNoti5 = ::Network::GETPACKETPOOL()->SEND_NEW();
////				pNoti5->MsgCat("%d%d%c", defender_gid, target_player_info.HP, ismonster);
////				pNoti5->MakePacket(CMD_SC_ATTACK);
////				pUser->Send(pNoti5);
////			}
////>>>>>>> .r774
////
////
////			//
//////			if( bFightEnd == true )
//////			{
//////				::Network::Packet * pNoti6 = ::Network::GETPACKETPOOL()->SEND_NEW();
//////				pNoti6->MsgCat("%d%d", winner_gid, loser_gid);
//////				pNoti6->MakePacket(CMD_SN_FIGHT_END);
//////				pSpace->SendAll(pNoti6);
//////
//////				::Logger::GETLOG()->ToFile(::Logger::DEBUG, "\t\tsend SN_FIGHT_END, winner_gid=%d, loser_gid=%d", winner_gid, loser_gid);
//////			}
////		}
////		else	// monster->monster
////		{
////			// FIXME: NOTHING TO DO
////		}
////	}
//}
//
////void
////CN_ATTACK::attackUserToUser(User * pUser, User * pTarget, NLogic::Space * pSpace, int damage_value, int & targetHP)
////{
////	pTarget->player_info.HP -= damage_value;
////	if( pTarget->player_info.HP <= 0 )
////	{
////		pTarget->player_info.HP = 0;
////		//bFightEnd = true;
////
////		int loser_gid = pTarget->GetGID();
////
////		pSpace->GetData()._winnerGID = pTarget->player_info.FighterGID;
////	}
////	targetHP = pTarget->player_info.HP;
////}
////
////void
////CN_ATTACK::attackUserToMonster(NLogic::Space * pSpace, NLogic::Monster * pMonster, int defender_gid, int damage_value, int & targetHP)
////{
////	targetHP = pMonster->DecreaseHP(damage_value);
////
////	// battle pet rebirth
////	if (pMonster->GetData().rebirth == true)
////	{
////		int new_hp = pMonster->GetData().max_hp * pMonster->GetData().rebirth_hp / 100;
////		pMonster->GetData().hp = new_hp;
////		targetHP = new_hp;
////
////		pMonster->GetData().rebirth = false;
////
////		::Network::Packet * pNoti = ::Network::GETPACKETPOOL()->SEND_NEW();
////		pNoti->MsgCat("%c%d%c", 0, defender_gid, new_hp);
////		pNoti->MakePacket(CMD_SC_REBIRTH_DIRECT);
////
////		pSpace->SendAll(pNoti);
////	}
////}
////
////void
////CN_ATTACK::attackMonsterToUser(User * pUser, User * pTarget, NLogic::Space * pSpace, int damage_value, int & targetHP)
////{
////	pTarget->player_info.HP -= damage_value;
////	if( pTarget->player_info.HP <= 0 )
////	{
////		pTarget->player_info.HP = 0;
////		//bFightEnd = true;
////
////		int loser_gid = pTarget->GetGID();
////
////		pSpace->GetData()._winnerGID = pTarget->player_info.FighterGID;
////	}
////	targetHP = pTarget->player_info.HP;
////}
//
//} /*NBattle*/ } /*NCommand*/ } /*ProjectZ*/
